//
//  XKStatus.swift
//  XKWeibo
//
//  Created by 小k on 15/11/13.
//  Copyright © 2015年 小k. All rights reserved.
//

import UIKit

class XKStatus: NSObject {

    /// 微博创建时间
    var created_at: String?
    /// 微博ID
    var id: Int = 0
    /// 微博信息类容
    var text: String?
    /// 微博来源
    var source: String?
    /// 缩略图配图字典数组
    var pic_urls: [[String: String]]?
    /// 用户模型
    var user:XKUserInfo?
    /// 被转发微博的字段
    var retweeted_status: XKStatus?
    
    /// 重写构造方法
    init (dict:[String: AnyObject]) {
        super.init()
        // kvc
        setValuesForKeysWithDictionary(dict)
    }
    
    // 重写setValueForKey 方法--> 因为模型中包含自定义对象
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            // 判断value 是否有值
            if let dict = value as? [String: AnyObject] {
                user = XKUserInfo(dict: dict)
            }
            return
        }
        
        // 判断 key 是否是 retweeted_status
        if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = XKStatus(dict: dict)
            }
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    /// 输出详细信息
    override var description: String {
        let keys = ["created_at", "id", "text", "source", "user", "pic_urls", "retweeted_status"]
        return dictionaryWithValuesForKeys(keys).description
    }
    
}
